<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var p = {
      name: '拖鞋军',
      _age: 10,//数据属性
      say: function () {
        console.log('开干');
      }
    }
    console.log(p);
    Object.defineProperty(p, 'age', {
      configurable: true,
      enumerable: false,
      get: function () {
        return this._age;
      },
      set: function (value) {
        if (value < 0 || value >= 150) {
          this._age = 0;
        } else {
          this._age = value;
        }
      }
    })
    Object.defineProperty(p, 'sex', {
      configurable: false,//是否可删除
      enumerable: false,//是否可枚举
      value: '男',//默认值
      writable: false,// 是否可修改
    })
    p.age = 200
    p.sex = "女"
    delete p.sex
    console.log(p);
    console.log(Object.keys(p));//可枚举的属性
    console.log(Object.getOwnPropertyNames(p));//所有属性
  </script>
</body>

</html>